package com.study.ssm.mybatis.spring;

import com.study.ssm.mybatis.dao.UserMapper;
import com.study.ssm.mybatis.entity.User;
import com.study.ssm.mybatis.service.UserService;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.beans.Introspector;

/**
 * @author zhoujunlin
 * @date 2023年07月20日 19:19
 * @desc
 */
public class TestApplicationContext01 {

    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/mybatis/applicationContext01.xml");

    public static void main(String[] args) {
        String simpleName = TestApplicationContext01.class.getSimpleName();
        System.out.println("simpleName = " + simpleName);
        // Spring生成beanName的方式
        String simpleBeanName = Introspector.decapitalize(simpleName);
        System.out.println("simpleBeanName = " + simpleBeanName);
    }

    @Test
    public void test01() {
        UserMapper userMapper = ctx.getBean("userMapper", UserMapper.class);

        userMapper.saveUser(new User("zhoujl666", "66666"));

        // spring-mybatis的数据库连接有Druid数据源创建的 默认是自动提交的

    }

    @Test
    public void test02() {
        UserService userService = ctx.getBean("userService", UserService.class);
        userService.save(new User("eeeeeeeeee", "uuuu"));
    }

}
